/**
 * request 网络请求工具
 * 更详细的 api 文档: https://github.com/umijs/umi-request
 */
import { extend } from 'umi-request';
import { notification } from 'antd';
import { Base64 } from 'js-base64';

/**
 * 配置request请求时的默认参数
 */
const authRequest = extend({
  prefix: 'http://127.0.0.1:33001',
  mode: 'cors',
  cache: "force-cache",
  getResponse: true,
  credentials: 'include', // 默认请求是否带上cookie
});

authRequest.interceptors.response.use((response, options) => {
  if(response.headers.get('x-platform-res-code') == undefined){
    return response;
  }
  if(response.headers.get('x-platform-res-code') != "00000000"){
    console.log(Base64.decode(response.headers.get('x-platform-res-message')));
  }
  response.ok = true;
  return response;
});

export default authRequest;
